package projectwork.shchuangge.cn.com.newproject.adapter;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import projectwork.shchuangge.cn.com.newproject.R;

/**
 * Created by 赵航 on 2017/6/20.
 */

public class ChoiceFragmentListAdpter extends BaseAdapter {
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what == 1){
                Bundle data = msg.getData();
                String  power = (String) data.get("signalPower");
                if (mOnImageItemClicke!=null){
                    mOnImageItemClicke.onImageItemClicke(power);
                }
            }

        }
    };
    private List mList;
    public ChoiceFragmentListAdpter(List<Integer> list) {
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList==null?0:mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(viewGroup.getContext(), R.layout.choiceitem_list, null);
            viewHolder.mBigImageView=convertView.findViewById(R.id.choice_items_big_iamges);
            viewHolder.mOneImageView = convertView.findViewById(R.id.choice_list_botome_first_images);
            viewHolder.mTwoImageView = convertView.findViewById(R.id.choice_list_botome_seconde_images);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();

        }
            viewHolder.mBigImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Message message = new Message();
                    //可以接受Been对象等数据
                    Bundle bundle = new Bundle();
                    bundle.putString("signalPower", "这是第一个");
                    message.what = 1;
                    message.setData(bundle);
                    mHandler.sendMessage(message);

                }
            });
        viewHolder.mOneImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //同 new Message();
                    Message message = mHandler.obtainMessage();

                    //可以接受Been对象等数据
                    Bundle bundle = new Bundle();
                    bundle.putString("signalPower", "这是下面第一个");
                    message.what = 1;
                    message.setData(bundle);
                    mHandler.sendMessage(message);

                }
            });
        viewHolder.mTwoImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    //同 new Message();
                    Message message = mHandler.obtainMessage();
                    //可以接受Been对象等数据
                    Bundle bundle = new Bundle();
                    bundle.putString("signalPower", "这是下面第二个");
                    message.what = 1;
                    message.setData(bundle);
                    mHandler.sendMessage(message);

                }
            });


        return convertView;
    }



    class ViewHolder{
        TextView mTextView;
        ImageView mBigImageView;
        ImageView mOneImageView;
        ImageView mTwoImageView;
        ImageView mThreeImageView;


    }
  public interface OnImageItemClicke {
        public void onImageItemClicke(String s);
    }
    private OnImageItemClicke mOnImageItemClicke;

    public void setOnImageItemClickeListener(OnImageItemClicke onImageItemClickeListener){
        this.mOnImageItemClicke = onImageItemClickeListener;
    }
}
